package com.ruyuan.eshop.data.migrate.tool.controller;

import com.ruyuan.eshop.data.migrate.tool.core.JsonResult;
import com.ruyuan.eshop.data.migrate.tool.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 简单检查数据的程序
 *
 * @author zhonghuashishan
 * @version 1.0
 */
@RestController
public class CheckDataController {

    @Autowired
    private TargetAfterSaleInfoService targetAfterSaleInfoService;

    @Autowired
    private TargetAfterSaleItemService targetAfterSaleItemService;

    @Autowired
    private TargetAfterSaleLogService targetAfterSaleLogService;

    @Autowired
    private TargetAfterSaleRefundService targetAfterSaleRefundService;

    @Autowired
    private TargetOrderAmountService targetOrderAmountService;

    @Autowired
    private TargetOrderAmountDetailService targetOrderAmountDetailService;

    @Autowired
    private TargetOrderAutoNoService targetOrderAutoNoService;

    @Autowired
    private TargetOrderCancelScheduledTaskService targetOrderCancelScheduledTaskService;

    @Autowired
    private TargetOrderDeliveryDetailService targetOrderDeliveryDetailService;

    @Autowired
    private TargetOrderInfoService targetOrderInfoService;

    @Autowired
    private TargetOrderItemService targetOrderItemService;

    @Autowired
    private TargetOrderPaymentDetailService targetOrderPaymentDetailService;

    @Autowired
    private TargetTendConsistencyTaskService targetTendConsistencyTaskService;


    /**
     * 查看目标库中各个逻辑表的最大主键ID值，用来跟旧库中的各个表的最大主键ID值进行比较
     * @return
     */
    @GetMapping("/listTargetTableMaxId")
    public JsonResult<Map<String, Object>> listTargetTableMaxId() {

        Map<String, Object> map = new HashMap<>();

        // after_sale_info表
        Long afterSaleInfoMaxId = targetAfterSaleInfoService.getMaxId();
        map.put("afterSaleInfoMaxId", afterSaleInfoMaxId);

        // after_sale_item表
        Long afterSaleItemMaxId = targetAfterSaleItemService.getMaxId();
        map.put("afterSaleItemMaxId", afterSaleItemMaxId);

        // after_sale_log表
        Long afterSaleLogMaxId = targetAfterSaleLogService.getMaxId();
        map.put("afterSaleLogMaxId", afterSaleLogMaxId);

        // after_sale_refund表
        Long afterSaleRefundMaxId = targetAfterSaleRefundService.getMaxId();
        map.put("afterSaleRefundMaxId", afterSaleRefundMaxId);

        // order_amount_detail表
        Long orderAmountDetailMaxId = targetOrderAmountDetailService.getMaxId();
        map.put("orderAmountDetailMaxId", orderAmountDetailMaxId);

        // order_amount表
        Long orderAmountMaxId = targetOrderAmountService.getMaxId();
        map.put("orderAmountMaxId", orderAmountMaxId);

        // order_auto_no表
        Long orderAutoNoMaxId = targetOrderAutoNoService.getMaxId();
        map.put("orderAutoNoMaxId", orderAutoNoMaxId);

        // order_cancel_scheduled_task表
        Long orderCancelScheduledMaxId = targetOrderCancelScheduledTaskService.getMaxId();
        map.put("orderCancelScheduledMaxId", orderCancelScheduledMaxId);

        // order_delivery_detail表
        Long orderDeliveryDetailMaxId = targetOrderDeliveryDetailService.getMaxId();
        map.put("orderDeliveryDetailMaxId", orderDeliveryDetailMaxId);

        // order_info表
        Long orderInfoMaxId = targetOrderInfoService.getMaxId();
        map.put("orderInfoMaxId", orderInfoMaxId);

        // order_item表
        Long orderItemMaxId = targetOrderItemService.getMaxId();
        map.put("orderItemMaxId", orderItemMaxId);

        // order_payment_detail表
        Long orderPaymentDetailMaxId = targetOrderPaymentDetailService.getMaxId();
        map.put("orderPaymentDetailMaxId", orderPaymentDetailMaxId);

        // ruyuan_tend_consistency_task表
        Long ruyuanTendConsistencyTaskMaxId = targetTendConsistencyTaskService.getMaxId();
        map.put("ruyuanTendConsistencyTaskMaxId", ruyuanTendConsistencyTaskMaxId);

        return JsonResult.buildSuccess(map);
    }

}